package com.zareal.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zareal.domain.Emp;
import com.zareal.dot.GetProductDto;
import com.zareal.dot.PutApplicationDto;
import com.zareal.feign.ProductFeignClient;
import com.zareal.feign.PurChaseFeignClient;
import com.zareal.feign.StorageFeignClient;
import com.zareal.mapper.EmpMapper;
import com.zareal.result.JSONResult;
import com.zareal.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Wilson
 * @since 2022-09-28
 */
@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements IEmpService {
    @Autowired
    private ProductFeignClient productFeignClient;

    @Autowired
    private StorageFeignClient storageFeignClient;

    @Autowired
    private PurChaseFeignClient purChaseFeignClient;

    @Override
    public JSONResult getProduct(Long id) {
        // 获取了指定商品信息
        Map product = (Map)productFeignClient.get(id).getData();
        Integer number = (Integer)storageFeignClient.get(id).getData();
        GetProductDto getProductDto = new GetProductDto(
                Long.valueOf(product.get("id").toString()),
                (String) product.get("name"),
                (String)product.get("pruductType"),
                (Integer)product.get("price"),
                number);
        return JSONResult.success(getProductDto);
    }
    // 查询所有
    @Override
    public JSONResult getAllProduct() {
        return productFeignClient.list();
    }
    // 入库
    @Override
    public JSONResult putStorage(GetProductDto getProductDto) {
        // 调用库存入库
        JSONResult jsonResult = storageFeignClient.putStorage(getProductDto);
        return JSONResult.success(jsonResult.getData());
    }
    // 出库
    @Override
    public JSONResult outStorage(GetProductDto getProductDto) {
        JSONResult jsonResult = storageFeignClient.outStorage(getProductDto);
        return JSONResult.success(jsonResult.getData());
    }

    @Override
    public JSONResult outOfStock() {
        return storageFeignClient.outOfStock();
    }

    @Override
    public JSONResult putApplication(PutApplicationDto putApplicationDto) {
        return purChaseFeignClient.purcharseProduct(putApplicationDto);
    }

    @Override
    public JSONResult passApplication(Long id) {
        return purChaseFeignClient.passApplication(id);
    }

    @Override
    public JSONResult failApplication(Long id) {
        return purChaseFeignClient.failApplication(id);
    }
}
